package experiment2.task2;


import experiment2.task1.Person;

import java.io.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

/**
 * @author 冯永龙
 * @date 2021/3/16 15:22
 */
public class PersonProxy implements PersonIntf {
    private Person person;
    private ArrayList<String> str = new ArrayList<>();  //将日志存入str
    private String date;

    public PersonProxy(Person person) {
        this.person = person;
    }

    public ArrayList<String> getStr() {
        return str;
    }

    @Override
    public void setName(String name) {
        date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        str.add("时间：" + date + " " + "方法名称：" + "setName " + "参数：" + name);
        person.setName(name);
    }

    @Override
    public void setSex(String sex) {
        date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        str.add("时间：" + date + " " + "方法名称：" + "setSex " + "参数：" + sex);
        person.setSex(sex);
    }

    @Override
    public void setAge(Integer age) {
        date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        str.add("时间：" + date + " " + "方法名称：" + "setAge " + "参数：" + age);
        person.setAge(age);
    }

    @Override
    public void setIdNo(String idNo) {
        date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        str.add("时间：" + date + " " + "方法名称：" + "setIdNo " + "参数：" + idNo);
        person.setIdNo(idNo);
    }

    @Override
    public void setMerried(boolean merried) {
        date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        str.add("时间：" + date + " " + "方法名称：" + "setMerried " + "参数：" + merried);
        person.setMerried(merried);
    }
}

